﻿@{
    ViewBag.Title = "司机日报表";
    Layout = "~/Areas/IM/Views/Shared/_Layout.cshtml";
}
@section Scripts{
    <script type="text/javascript">
        $(document).ready(function () {
            DisableBackspace();
            RevistMainGrid();
        });
        $(window).resize(function () {
            $.setGridWithSearchBar("#TableForm", "#tbb", "#DriverReportMain");
        });

        var EditRowID = "";
        var EditBanci = "";
        var EditRowDate = new Date();
        //全局变量
        var DworkID = '@ViewData["selfWorkCode"]';
        var LastModifier = '@ViewData["LastModifier"]';
        var SAmbulance;  //选择的车辆车牌号码  (用于取昨天的下班路码赋值给今天的上班路码 根据车牌号  2016-3-16)
        var YesdayOffDutyKM;
        var YesdayOffDutyDipstick;
        //是否是非生产用车页面的编辑取的值
        var IFNonPOnDutyKM;
        var IFNonPOnDutyDipstick;


        //加载列表数据
        function RevistMainGrid() {
            $('#DriverReportMain').datagrid({
                width: 'auto',
                height: 'auto',
                // fitColumns: true, //真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
                loadMsg: '数据加载中,请稍后……',
                url: '@Url.Content("~/DD/DriverReport/GetReportMain")',
                striped: true,
                singleSelect: true,
                pagination: true,//启用分页，默认每页10行
                rownumbers: true,//显示页码，默认 提供 10 - 50 的页容量选择下拉框
                pageSize: 15,//设置 页容量5
                pageList: [10, 15, 20],//设置 页容量下拉框
                queryParams: {
                    DworkID: DworkID
                },
                frozenColumns: [[
                    { field: "ID", hidden: true },
                    {
                        field: "detail", title: "填日报", width: '8%', align: "center",
                        formatter: function (value, row, index) {

                            return '<a  class="linkURLcls" onclick="openDetailURL(\'' + row.ID + '\');"  href="javascript:void(0)">填日报</a>';
                        }
                    },
                     {
                         field: "deletez", title: "撤销", width: '6%', align: "center",
                         formatter: function (value, row, index) {
                             return '<a  id="adelete" class="linkURLZZ" onclick="deleteDetailURL(\'' + row.ID + '\');"  href="javascript:void(0)">撤销</a>';
                         }
                     },
                    { field: "FillState", title: "日报状态", width: '12%', align: "center" },
                    { field: "AgentWorkID", title: "填写人工号", width: '7%', align: "center" },
                    { field: "AmbulanceNumber", title: "车辆", width: '9%', align: "center" },
                    { field: "ReportDate", title: "日报日期", width: '9%', align: "center", formatter: $.formatDate },
                    { field: "BanCi", title: "班次", width: '8%', align: "center" },
                    { field: "TaskTimes", title: "车次", width: '8%', align: "center" },
                    { field: "LastModifyTime", title: "最后填写时间", width: '13%', align: "center", formatter: $.formatTime },
                    { field: "LastModifier", title: "最后填写人", width: '8%', align: "center" },
                    {
                        field: "detail2", title: "预览", width: '6%', align: "center",
                        formatter: function (value, row, index) {
                            return '<a  class="linkURL" onclick="openPrintURL(\'' + row.ID + '\');"  href="javascript:void(0)">预览</a>';
                        }
                    },
                    //2018-12-06 zch
                    {
                        field: "FillPerson", title: "解款", width: '6%', align: "center",
                        formatter: function (value, row, index) {
                            if (value == "" || value == undefined)
                                return '<a  class="linkPay" onclick="openPayInDialog(\'' + row.ID + '\');"  href="javascript:void(0)">解款</a>';
                            else
                                // return '<span style ="color:red;">已解款</span>';
                                return value;
                        }
                    }

                ]],
                toolbar: [
                  {
                      id: 'btnAdd',
                      text: '选任务',
                      iconCls: 'icon-add',
                      handler: function () {

                          $('#RevisitAddTask').dialog('open'); //打开 请选择任务 弹层页
                          // EditRowDate = "";
                          initPickTaskGrid(); //加载弹层页列表数据

                      }
                  }, '-',
                    {
                        id: 'btnAddMore',
                        text: '继续添加',
                        iconCls: 'icon-add',
                        handler: function () {
                            var row = $('#DriverReportMain').datagrid('getSelected');
                            if (row) {
                                //2016-7-6 zch 添加判断，如果已被分站长勾选，就不能继续添加
                                if (row.ReportState == null || row.ReportState != "已勾选") {
                                    EditRowID = row.ID;
                                    EditBanci = row.BanCi;
                                    $('#RevisitAddTask').dialog('open');
                                    initPickTaskGrid();
                                }
                                else { $.messager.alert('系统提示', '已被分站长勾选，不能继续添加！'); }
                            }
                            else {
                                $.messager.alert('系统提示', '请选择要修改的数据行！');
                            }
                        }
                    }, '-',
                 {
                     id: 'btnAdd',
                     text: '非生产用车填报',
                     iconCls: 'icon-add',
                     handler: function () {
                         $('#FillNonProductDialog').dialog('open');
                         initNonProductFill(-1);
                     }
                 }
                ],

                onLoadSuccess: function (data) {
                    $('.linkPay').linkbutton({
                        text: '<span style ="color:red;">解款</span>',
                        plain: true,
                        iconCls: 'icon-save'
                    });
                    $('.linkURLcls').linkbutton({
                        text: '填日报',
                        plain: true,
                        iconCls: 'icon-save'
                    });
                    $('.linkURL').linkbutton({
                        text: '预览',
                        plain: true,
                        iconCls: 'icon-print'
                    });
                    $('.linkURLZZ').linkbutton({
                        text: '撤销',
                        plain: true,
                        iconCls: 'icon-custom-cJinYong'
                    });
                }

            });
            $.setGridWithSearchBar("#TableForm", "#tbb", "#DriverReportMain");
        }

        //点击填日报后 进行的内容
        function openDetailURL(rowid) {
            //先判断 是否是非生产用车 的情况
            $.ajax({
                type: 'POST',
                url: '@Url.Content("~/DD/DriverReport/IFExistReportDate")',
                data:
                    {
                        rowid: rowid
                    },
                dataType: "json",
                success: function (jsData) {
                    var banci = jsData.drinfo.BanCi;
                    if (banci == "非生产用车") {
                        initNonProductFill(rowid);

                    }
                    else {
                        initFill(rowid);
                    }
                }
            });


        }

        function openPrintURL(rowid) {
            var url = '@Url.Content("~/BB/TJ/DriverReportPrint/?ID=")' + rowid;
            window.open(url);
        }

        function deleteDetailURL(deleterowID) {
            document.getElementById('adelete').disabled = true; //避免重复点击，多次提交
            $.messager.confirm('确认', '您确认想要删除记录吗？', function (r) {
                if (r) {
                    $.ajax({
                        type: 'POST',
                        url: '@Url.Content("~/DD/DriverReport/deleteReportDate")',
                        data:
                            {
                                deleteRowID: deleterowID
                            },
                        dataType: "json",
                        success: function (jsData) {
                            $.handleJsonResult(jsData, function () {
                                // Materials.length = 0;
                                $("#DriverReportMain").datagrid("reload");
                                document.getElementById('adelete').disabled = false;
                                //  EditRowID = "";
                            });
                        }
                    });
                }
            });
        }
    </script>
}
<div id="TableForm" class="easyui-layout" style="width:auto; height: auto; margin-left: auto; margin-right: auto">
    <div data-options="region:'center',title:'司机日报表',iconCls:'icon-custom-cPrice'">
        <div id="tbb" style="padding: 5px; height: auto">
        </div>
        <div data-options="region:'center'" style="background: #fafafa; overflow: hidden">
            <table id="DriverReportMain" border="0"></table>
        </div>
    </div>
</div>
@Html.Partial("~/Areas/DD/Views/DriverReport/DriverReportPick.cshtml")
@Html.Partial("~/Areas/DD/Views/DriverReport/DriverReportPickMain.cshtml")
@Html.Partial("~/Areas/DD/Views/DriverReport/DriverReportFill.cshtml")
@Html.Partial("~/Areas/DD/Views/DriverReport/NonProductionReportFill.cshtml")
@Html.Partial("~/Areas/DD/Views/DriverReport/PayInView.cshtml")
